package com.ytjj.qmyx.supplychain.service;

import com.google.common.base.Joiner;
import com.ytjj.qmyx.supplychain.common.model.response.Api99Response;
import com.ytjj.qmyx.supplychain.mapper.ApiDataInfoMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.YxApiDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@Service
public class ApiDataInfoService {
    @Resource
    private ApiDataInfoMapper apiDataInfoMapper;

    public void save99APIData(Api99Response response) {
        YxApiDataInfo bean = new YxApiDataInfo();
        bean.setTitle(response.getTitle());
        bean.setSubTitle(response.getSubTitle());
        bean.setDescUrl(null);
        if (!CollectionUtils.isEmpty(response.getSkuImgs())) {
            bean.setSkuImgs(Joiner.on(",").join(response.getSkuImgs()));
        }
        if (!CollectionUtils.isEmpty(response.getDescImgList())) {
            bean.setDescImgs(Joiner.on(",").join(response.getDescImgList()));
        }
        if (!CollectionUtils.isEmpty(response.getImagesList())) {
            bean.setImages(Joiner.on(",").join(response.getImagesList()));
        }
        bean.setCreateTime(new Date());
        bean.setRequestUrl(response.getRequestUrl());
        apiDataInfoMapper.insert(bean);
    }
}
